// interface PersonEx1 {
//   name: string;
//   age: number;
//   address: string;
// }

// type NameAndAge = Pick<PersonEx1, "name" | "age">;
// const person: NameAndAge = { name: "John", age: 34 };

function pickProperties<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
  const result: Partial<T> = {};

  for (const key of keys) {
    result[key] = obj[key];
  }

  return result as Pick<T, K>;
}

interface Person {
  name: string;
  age: number;
  address: string;
}
const person: Person = {
  name: "John",
  age: 25,
  address: "123 Main St",
};
const nameAndAge = pickProperties(person, ["name", "age"]); // 只包含name 和 age 属性
console.log(nameAndAge); // 输出: { name: 'John', age:25 }
